<script setup lang="ts">
import axios from 'axios'
import { watchEffect, ref } from 'vue'
import type { ArticleResData, ArticleItem } from '../types/data'
const props = defineProps<{
  channelId: number
}>()

const articles = ref<ArticleItem[]>([])

watchEffect(async () => {
  const res = await axios.get<ArticleResData>('http://geek.itheima.net/v1_0/articles', {
    params: {
      channel_id: props.channelId,
      timestamp: Date.now()
    }
  })
  articles.value = res.data.data.results
})
</script>

<template>
  <div class="article-list">
    <div class="article-item" v-for="(item, index) in articles" :key="index">
      <p class="title">{{ item.title }}</p>
      <img class="img" :src="img" alt="" v-for="img in item.cover.images" />
      <div class="info">
        <span>{{ item.aut_name }}</span>
        <span>{{ item.comm_count }}评论</span>
        <span>{{ item.pubdate }}</span>
      </div>
    </div>
  </div>
</template>
